<?php

namespace app\model;

use think\Model;

class Order extends Model
{
    protected $pk = 'orderid';

    public function task() {
        return $this->hasOne('Task', 'taskid', 'taskid');
    }

    public function taskInfo() {
        return $this->hasOne('TaskInfo', 'id', 'taskinfoid');
    }

    public function buyerInfo() {
        return $this->hasOne('MemberBuyerInfo', 'userid', 'userid');
    }

    public function getCommissionAttr($value){return sprintf("%.2f",$value);}
    public function getChargecommissionAttr($value){return sprintf("%.2f",$value);}
    public function getShopDepositAttr($value){return sprintf("%.2f",$value);}
    public function getAdvancepaymentAttr($value){return sprintf("%.2f",$value);}
    
    public function getImgurl1Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl2Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl3Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl4Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl5Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl6Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl7Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl8Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl9Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl10Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl11Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl12Attr($value){return \tool\Url::FileConversionUrl($value);}
    public function getImgurl13Attr($value){return \tool\Url::FileConversionUrl($value);}


    public function getStatusAttr($value) {
        $status = [
            0 => '待放出',
            1 => '未接单',
            2 => '未操作',
            3 => '待返款发货',
            4 => '待评价',
            5 => '待确认',
            6 => '已完成',
            10 => '已撤销',
            20 => '申诉成功'
        ];
        return $status[$value];
    }

    public static function getList($where = [])
    {
        $data = static::field('orderid,taskid,commission,status,receive_time,shop_deposit,complete_time')
            ->where($where)
            ->order('receive_time desc')
            ->paginate(20);
        foreach ($data as &$vo) {
            $vo->task;
            $vo['imgurl'] = $vo->task['imgurl'];
            $vo['buyprice'] = $vo->task['buyprice'];
            $vo['tasktype'] = $vo->task['tasktype'];
            unset($vo->task);
            unset($vo->taskid);
        }
        return $data;
    }

}